package com.douqu.game.core.web.request;

import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.StringUtils;

import java.util.List;

/**
 * @author wangzhenfei
 *         2018-03-16 10:11
 */
public class MajorBattleParam {
    private String objectIndex;
    private int majorType;
    private int battleType;
    private String param;
    private List<GoodsData> battleResult;

    public MajorBattleParam(String objectIndex, int majorType, int battleType, String param) {
        this.objectIndex = objectIndex;
        this.majorType = majorType;
        this.battleType = battleType;
        this.param = param;
    }

    public MajorBattleParam(String value){
        try {
            String[] s = value.split(ConstantFactory.UNDERLINE);
            objectIndex = s[0];
            majorType = Integer.valueOf(s[1]);
            battleType = Integer.valueOf(s[2]);
            param = s[3];
        } catch (Exception e) {
//            e.printStackTrace();
        }
    }

    public String getBattleStringParam(){
        return objectIndex + ConstantFactory.UNDERLINE + majorType + ConstantFactory.UNDERLINE + battleType +
                ConstantFactory.UNDERLINE + param;
    }

    public boolean checkError(){
        LogUtils.debug("专业战斗参数检测：" + this);
        if(StringUtils.isNullOrEmpty(objectIndex)){
            return true;
        }
        if(SGCommonProto.E_MAJOR_TYPE.forNumber(majorType) == null){
            return true;
        }

        if(SGCommonProto.E_MAJOR_BATTLE_TYPE.forNumber(battleType) == null){
            return true;
        }

        return false;
    }


    public String getObjectIndex() {
        return objectIndex;
    }

    public int getMajorType() {
        return majorType;
    }

    public int getBattleType() {
        return battleType;
    }

    public String getParam() {
        return param;
    }

    @Override
    public String toString() {
        return "MajorBattleParam{" +
                "objectIndex='" + objectIndex + '\'' +
                ", majorType=" + majorType +
                ", battleType=" + battleType +
                ", param='" + param + '\'' +
                '}';
    }
}
